﻿<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.Scripting.Hosting" %>
<%@ Import Namespace="Ruandao.MiniFace" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Template template = new Template("/Templates/Default/", "Page/test.htm");

        TextWriter writer = Response.Output;

        TemplateContext templateContext = new TemplateContext();
        ScriptScope pythonScope = templateContext.PythonScope;
        var httpContext = HttpContext.Current;

        dynamic ViewBag = new DynamicDictionary<object>() as DynamicDictionary<object>;

        ViewBag.TestValue = "欢迎使用软道模板系统!";
        var dict = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
        for (int i = 0; i < 3; i++)
        {
            var two = new Dictionary<string, Dictionary<string, string>>();
            for (int j = 0; j < 3; j++)
            {
                var three = new Dictionary<string, string>();
                for (int k = 0; k < 3; k++)
                {
                    string key3 = "CCCCC" + i.ToString() + j.ToString() + k.ToString();
                    three.Add(key3, key3 + ":  aaa,bbb, ccc, ....");
                }
                string key2 = "BBBBB" + i.ToString() + j.ToString();
                two.Add(key2, three);
            }
            dict.Add("AAAAA" + i.ToString(), two);
        }

        ViewBag.DictTree = dict;

        pythonScope.SetVariable("ViewBag", ViewBag);

        pythonScope.SetVariable("HttpContext", httpContext);
        pythonScope.SetVariable("Request", httpContext.Request);
        pythonScope.SetVariable("QueryString", httpContext.Request.QueryString);
        pythonScope.SetVariable("QueryBag", httpContext.Request.QueryString.AsDynamic());
        pythonScope.SetVariable("Server", httpContext.Server);
        pythonScope.SetVariable("Response", httpContext.Response);
        pythonScope.SetVariable("User", httpContext.User);
        pythonScope.SetVariable("Items", httpContext.Items);

        template.Render(templateContext, writer);


        Response.End();
    }
</script>